package cn.hdu.liang.ch1;

public class ThreadDemo2 {
    public static void main(String[] args) {

        Runnable r = () -> {
            String name = Thread.currentThread().getName();
            int count = 0;
            while(!Thread.interrupted()) {
                System.out.println(name + ": " + count++);
            }
        };

        Thread thdA = new Thread(r);
        Thread thdB = new Thread(r);
        thdA.start();
        thdB.start();

        while(true) {
            double n = Math.random();
            if(n >= 0.49999 && n <= 0.50001) {
                break;
            }
        }

        thdA.interrupt();
        thdB.interrupt();
    }
}